/**
 * @namespace utils.Predicates
 * 配合 {@link utils.ArraysConstructor} 使用
 * Arrays.filter(source, Predicates.newPropValEqPredicate('propName', val));
 *
 * Created with IntelliJ IDEA.
 * User: zhengry
 * Date: 2014/11/18
 * Time: 16:59
 */
define([], function () {
    return function () {
        return {
            /**
             * 属性相等的匹配器
             * @param {String} propName 属性名称
             * @param {String} val 要比较的值
             * @return {function(Object):boolean} Predicate
             */
            newPropValEqPredicate: function (propName, val) {
                return this.newPropPredicate(propName, this.newEqPredicate(val));
            },
            newPropPredicate: function (propName, predicate) {
                return function (element) {
                    if (element.hasOwnProperty(propName)) {
                        return predicate(element[propName]);
                    }
                    return false;
                }
            },
            newEqPredicate: function (value) {
                return function (element) {
                    return value === element;
                }
            },
            not: function (predicate) {
                return function (element) {
                    return !predicate(element);
                };
            }
        }
    }
});